package com.jiankangjin.appspos.controller;

import com.jiankangjin.appspos.service.IMerchantServices;
import com.jiankangjin.appspos.services.UserServices;
import com.jiankangjin.appspos.vo.*;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jiankangjin.appspos.services.OrderServieces;
import com.jiankangjin.appspos.util.CheckToken;
import com.jiankangjin.appspos.util.StringUtil;

@Controller
public class OrderController {
	private static final transient Log logger = LogFactory
			.getLog(OrderController.class);

	@Autowired
	private OrderServieces orderServieces;
	@Autowired
	private UserServices userService;
	@Autowired
	private IMerchantServices merchantServices;


	/**
	 * 创建订单
	 */
	@RequestMapping(value = "/create_order", method = RequestMethod.POST)
	@ResponseBody
	public CreateOrderVo createOrder(
			@RequestParam(required = false) String token,
			@RequestParam(required = false) String version,
			@RequestParam(required = false) String merchant_id,
			@RequestParam(required = false) String merchant_order_id,
			@RequestParam(required = false) String total_fee,
			@RequestParam(required = false) String currency,
			@RequestParam(required = false) String content,
			@RequestParam(required = false) String detail,
			@RequestParam(required = false) String is_tip,
			@RequestParam(required = false) String buyer_name,
			@RequestParam(required = false) String buyer_cellphone,
			@RequestParam(required = false) String comment,
			
			@RequestParam(required = false) String busi_type,
			
            @RequestParam(required = false) String order_total_fee,//订单总额-折扣金额=订单金额(订单表中的ordAmt)
            @RequestParam(required = false) String discount_fee,
            @RequestParam(required = false) String discount_comment,

			@RequestParam(required = false) String local_pay_ssn,
			@RequestParam(required = false) String fee,
			@RequestParam(required = false) String channel_id,
			@RequestParam(required = false) String buyer_token,
			@RequestParam(required = false) String buyer_voucher,
			@RequestParam(required = false) String channel_type,
			
			@RequestParam(required = false) String sign) {
		StringBuilder sb = new StringBuilder();
		sb.append("token=" + token);
		sb.append(" version=" + version);
		sb.append(" merchant_id=" + merchant_id);
		sb.append(" merchant_order_id=" + merchant_order_id);
		sb.append(" total_fee=" + total_fee);
		sb.append(" currency=" + currency);
		sb.append(" content=" + content);
		sb.append(" detail=" + detail);
		sb.append(" is_tip=" + is_tip);
		sb.append(" buyer_name=" + buyer_name);
		sb.append(" buyer_cellphone=" + buyer_cellphone);
		sb.append(" comment=" + comment);
		
		sb.append(" busi_type=" + busi_type);
		
		sb.append(" order_total_fee=" + order_total_fee);
		sb.append(" discount_fee=" + discount_fee);
		sb.append(" discount_comment=" + discount_comment);
		
		sb.append(" local_pay_ssn=" + local_pay_ssn);
		sb.append(" fee=" + fee);
		sb.append(" channel_id=" + channel_id);
		sb.append(" buyer_token=" + buyer_token);
		sb.append(" buyer_voucher=" + buyer_voucher);
		sb.append(" channel_type=" + channel_type);
		
		sb.append(" sign=" + sign);
		if (logger.isInfoEnabled()) {
			logger.info("创建订单接口:" + sb);
		}
		CreateOrderVo createOrderVo = new CreateOrderVo();
		createOrderVo.setResp_status("9999");
		if (StringUtil.isEmpty(token)) {
			createOrderVo.setMsg("token不能为空");
			return createOrderVo;
		}
		if (StringUtil.isEmpty(merchant_order_id)) {
			createOrderVo.setMsg("merchant_order_id不能为空");
			return createOrderVo;
		}
		Integer _total_fee = 1;
		if (StringUtil.isEmpty(total_fee)) {
			createOrderVo.setMsg("total_fee不能为空");
			return createOrderVo;
		} else {
			if (StringUtil.isNotNum(total_fee)) {
				createOrderVo.setMsg("total_fee必须是数字");
				return createOrderVo;
			} else {
				_total_fee = Integer.parseInt(total_fee);
				if (_total_fee <= 0) {
					createOrderVo.setMsg("total_fee必须大于0");
					return createOrderVo;
				}
			}
		}
		Integer _order_total_fee = 1;
		if (StringUtil.isEmpty(order_total_fee)) {
			createOrderVo.setMsg("order_total_fee不能为空");
			return createOrderVo;
		} else {
			if (StringUtil.isNotNum(order_total_fee)) {
				createOrderVo.setMsg("order_total_fee必须是数字");
				return createOrderVo;
			} else {
				_order_total_fee = Integer.parseInt(order_total_fee);
				if (_order_total_fee <= 0) {
					createOrderVo.setMsg("order_total_fee必须大于0");
					return createOrderVo;
				}
			}
		}
		Integer _discount_fee = 0;
		if (StringUtil.isEmpty(discount_fee)) {
			createOrderVo.setMsg("discount_fee不能为空");
			return createOrderVo;
		} else {
			if (StringUtil.isNotNum(discount_fee)) {
				createOrderVo.setMsg("discount_fee必须是数字");
				return createOrderVo;
			} else {
				_discount_fee = Integer.parseInt(order_total_fee);
				if (_discount_fee < 0) {
					createOrderVo.setMsg("discount_fee必须大于等于0");
					return createOrderVo;
				}
			}
		}
		if (StringUtil.isEmpty(detail)) {
			createOrderVo.setMsg("detail不能为空");
			return createOrderVo;
		}

		if (StringUtil.isEmpty(buyer_cellphone)) {
			createOrderVo.setMsg("buyer_cellphone不能为空");
			return createOrderVo;
		}
		boolean _is_tip = true;

		if (StringUtil.isNotEmpty(is_tip)) {
			if (is_tip.toLowerCase().equals("false") || is_tip.equals("0")) {
				_is_tip = false;
			}
		}

		if (StringUtil.isEmpty(sign)) {
			createOrderVo.setMsg("sign不能为空");
			return createOrderVo;
		}
		
		if(StringUtil.isEmpty(merchant_id)){
			createOrderVo.setMsg("merchant_id商户号不能为空！");
			return createOrderVo;
		}

		String merchant_name = "SPOS_name";
		GetUserInfoVo userInfo = CheckToken.getUserInfo(token);
		if (!"0000".equals(userInfo.getResp_status())) {
			createOrderVo.setMsg("token 验证失败！");
			return createOrderVo;
		}
		String operator_id = userInfo.getUuid();
		String operator_name = userInfo.getUser_name();
		Integer _fee = 1;
		if (StringUtil.isNotEmpty(local_pay_ssn)) {
			// 如果本地支付流水不为空，不但创建订单而且支付
			if (StringUtil.isEmpty(fee)) {
				createOrderVo.setMsg("fee不能为空");
				return createOrderVo;
			} else {
				if (StringUtil.isNotNum(fee)) {
					createOrderVo.setMsg("fee必须是数字");
					return createOrderVo;
				} else {
					_fee = Integer.parseInt(fee);
					if (_fee <= 0) {
						createOrderVo.setMsg("fee必须大于0");
						return createOrderVo;
					}
					if (_fee > _total_fee) {
						createOrderVo.setMsg("fee不能大于total_fee");
						return createOrderVo;
					}
				}
			}
			if (StringUtil.isEmpty(channel_id)) {
				createOrderVo.setMsg("channel_id不能为空");
				return createOrderVo;
			}
			if (StringUtil.isEmpty(buyer_token)) {
				createOrderVo.setMsg("buyer_token不能为空");
				return createOrderVo;
			}
			if (StringUtil.isEmpty(buyer_voucher)) {
				createOrderVo.setMsg("buyer_voucher不能为空");
				return createOrderVo;
			}
			if (StringUtil.isEmpty(channel_type)) {
				createOrderVo.setMsg("channel_type不能为空");
				return createOrderVo;
			}
		}
		return orderServieces.createOrder(merchant_id, merchant_name,
				merchant_order_id, _total_fee, currency, content, detail,
				_is_tip, buyer_name, buyer_cellphone, comment, busi_type,
				operator_id, operator_name, order_total_fee, discount_fee,
				discount_comment, local_pay_ssn, _fee, channel_id, buyer_token,
				buyer_voucher, channel_type);
	}

	/**
	 * 订单支付
	 */
	@RequestMapping(value = "/pay_order", method = RequestMethod.POST)
	@ResponseBody
	public PayOrderVo payOrder(
			@RequestParam(required = false) String token,
			@RequestParam(required = false) String version,
			@RequestParam(required = false) String merchant_id,
			@RequestParam(required = false) String local_pay_ssn,
			@RequestParam(required = false) String order_id,
			@RequestParam(required = false) String fee,
			@RequestParam(required = false) String currency,
			@RequestParam(required = false) String channel_id,
			@RequestParam(required = false) String buyer_token,
			@RequestParam(required = false) String buyer_voucher,
			@RequestParam(required = false) String channel_type,
			@RequestParam(required = false) String sign) {
		StringBuilder sb = new StringBuilder();
		sb.append("token=" + token);
		sb.append(" version=" + version);
		sb.append(" merchant_id=" + merchant_id);
		sb.append(" local_pay_ssn=" + local_pay_ssn);
		sb.append(" order_id=" + order_id);
		sb.append(" fee=" + fee);
		sb.append(" currency=" + currency);
		sb.append(" channel_id=" + channel_id);
		sb.append(" buyer_token=" + buyer_token);
		sb.append(" buyer_voucher=" + buyer_voucher);
		sb.append(" channel_type=" + channel_type);
		sb.append(" sign=" + sign);
		if (logger.isInfoEnabled()) {
			logger.info("订单支付接口：" + sb);
		}
		PayOrderVo payOrderVo = new PayOrderVo();
		payOrderVo.setResp_status("9999");
		if (StringUtil.isEmpty(token)) {
			payOrderVo.setMsg("token不能为空");
			return payOrderVo;
		}
		if (StringUtil.isEmpty(local_pay_ssn)) {
			payOrderVo.setMsg("local_pay_ssn不能为空");
			return payOrderVo;
		}
		if (StringUtil.isEmpty(order_id)) {
			payOrderVo.setMsg("order_id不能为空");
			return payOrderVo;
		}
		Integer _fee = 1;
		if (StringUtil.isEmpty(fee)) {
			payOrderVo.setMsg("fee不能为空");
			return payOrderVo;
		} else {
			if (StringUtil.isNotNum(fee)) {
				payOrderVo.setMsg("fee必须是数字");
				return payOrderVo;
			} else {
				_fee = Integer.parseInt(fee);
				if (_fee <= 0) {
					payOrderVo.setMsg("fee必须大于0");
					return payOrderVo;
				}
			}
		}
		if (StringUtil.isEmpty(channel_id)) {
			payOrderVo.setMsg("channel_id不能为空");
			return payOrderVo;
		}
		if (StringUtil.isEmpty(buyer_token)) {
			payOrderVo.setMsg("buyer_token不能为空");
			return payOrderVo;
		}
		if (StringUtil.isEmpty(buyer_voucher)) {
			payOrderVo.setMsg("buyer_voucher不能为空");
			return payOrderVo;
		}
		if (StringUtil.isEmpty(channel_type)) {
			payOrderVo.setMsg("channel_type不能为空");
			return payOrderVo;
		}
		if (StringUtil.isEmpty(sign)) {
			payOrderVo.setMsg("sign不能为空");
			return payOrderVo;
		}

		GetUserInfoVo userInfo = null;
	    // Token验证
		userInfo = CheckToken.getUserInfo(token);
		if (!"0000".equals(userInfo.getResp_status())) {
			payOrderVo.setSub_deal_stauts("3002");
			payOrderVo.setMsg("token验证失败！");
			return payOrderVo;
		}
		return orderServieces.payOrder(token, local_pay_ssn, order_id, _fee,
				currency, channel_id, buyer_token, buyer_voucher, channel_type);
	}

	/**
	 * 订单支付状态确认
	 */
	@RequestMapping(value = "/get_pay_status", method = RequestMethod.POST)
	@ResponseBody
	public GetPayStatusVo getPayStatus(
			@RequestParam(required = false) String token,
			@RequestParam(required = false) String version,
			@RequestParam(required = false) String merchant_id,
			@RequestParam(required = false) String sub_deal_ssn,
			@RequestParam(required = false) String order_id,
			@RequestParam(required = false) String sign) {
		StringBuilder sb = new StringBuilder();
		sb.append("token=" + token);
		sb.append(" version=" + version);
		sb.append(" merchant_id=" + merchant_id);
		sb.append(" sub_deal_ssn=" + sub_deal_ssn);
		sb.append(" order_id=" + order_id);
		sb.append(" sign=" + sign);
		if (logger.isInfoEnabled()) {
			logger.info("订单支付状态确认接口：" + sb);
		}
		GetPayStatusVo getPayStatusVo = new GetPayStatusVo();
		getPayStatusVo.setResp_status("9999");
		if (StringUtil.isEmpty(token)) {
			getPayStatusVo.setMsg("token不能为空");
			return getPayStatusVo;
		}
		if (StringUtil.isEmpty(sub_deal_ssn)) {
			getPayStatusVo.setMsg("sub_deal_ssn不能为空");
			return getPayStatusVo;
		}
		if (StringUtil.isEmpty(order_id)) {
			getPayStatusVo.setMsg("order_id不能为空");
			return getPayStatusVo;
		}
		if (StringUtil.isEmpty(sign)) {
			getPayStatusVo.setMsg("sign不能为空");
			return getPayStatusVo;
		}

		GetUserInfoVo userInfo = null;
	    // Token验证
		userInfo = CheckToken.getUserInfo(token);
		if (!"0000".equals(userInfo.getResp_status())) {
				getPayStatusVo.setSub_deal_stauts("3002");
				getPayStatusVo.setMsg("token验证失败！");
				return getPayStatusVo;
			}
		return orderServieces.getPayStatus(token, sub_deal_ssn, order_id);
	}

	/**
	 * 交易查询
	 */
	@RequestMapping(value = "/search_order", method = RequestMethod.POST)
	@ResponseBody
	public SearchOrderVo searchOrder(
			@RequestParam(required = false) String token,
			@RequestParam(required = false) String version,
			@RequestParam(required = false) String order_date_begin,
			@RequestParam(required = false) String order_date_end,
			@RequestParam(required = false) String refund_date_begin,
			@RequestParam(required = false) String refund_date_end,
			@RequestParam(required = false) String search_word,
			@RequestParam(required = false) String order_id,
			@RequestParam(required = false) String order_stat,
			@RequestParam(required = false) String isTip,
			@RequestParam(required = false) String sign) {
		StringBuilder sb = new StringBuilder();
		sb.append("token=" + token);
		sb.append(" version=" + version);
		sb.append(" order_date_begin=" + order_date_begin);
		sb.append(" order_date_end=" + order_date_end);
		sb.append(" refund_date_begin=" + refund_date_begin);
		sb.append(" refund_date_end=" + refund_date_end);
		sb.append(" search_word=" + search_word);
		sb.append(" order_id=" + order_id);
		sb.append(" order_stat=" + order_stat);
		sb.append(" order_stat=" + isTip);
		sb.append(" sign=" + sign);
		if (logger.isInfoEnabled()) {
			logger.info("交易查询接口：" + sb);
		}
		SearchOrderVo searchOrderVo = new SearchOrderVo();
		searchOrderVo.setResp_status("9999");
		if (StringUtil.isEmpty(token)) {
			searchOrderVo.setMsg("token不能为空");
			return searchOrderVo;
		}
		if (StringUtil.isEmpty(sign)) {
			searchOrderVo.setMsg("sign不能为空");
			return searchOrderVo;
		}

		// 追加Token验证
		GetUserInfoVo userInfo = null;
		userInfo = CheckToken.getUserInfo(token);
		if (!"0000".equals(userInfo.getResp_status())) {
			searchOrderVo.setMsg("token 验证失败！");
			return searchOrderVo;
		}
		return orderServieces.searchOrder(token, order_date_begin,
				order_date_end, refund_date_begin, refund_date_end,
				search_word, order_id, order_stat,isTip);
	}

	/**
	 * 交易查询结果查看
	 */
	@RequestMapping(value = "/get_order_result", method = RequestMethod.POST)
	@ResponseBody
	public GetOrderResultVo getOrderResult(
			@RequestParam(required = false) String token,
			@RequestParam(required = false) String result_id,
			@RequestParam(required = false) String page,
			@RequestParam(required = false) String quantity,
			@RequestParam(required = false) String sign) {
		StringBuilder sb = new StringBuilder();
		sb.append("token=" + token);
		sb.append(" result_id=" + result_id);
		sb.append(" page=" + page);
		sb.append(" quantity=" + quantity);
		sb.append(" sign=" + sign);
		if (logger.isInfoEnabled()) {
			logger.info("交易查询结果查看接口：" + sb);
		}
		GetOrderResultVo getOrderResultVo = new GetOrderResultVo();
		getOrderResultVo.setResp_status("9999");
		if (StringUtil.isEmpty(token)) {
			getOrderResultVo.setMsg("token不能为空");
			return getOrderResultVo;
		}
		if (StringUtil.isEmpty(result_id)) {
			getOrderResultVo.setMsg("result_id不能为空");
			return getOrderResultVo;
		}
		Integer _page = 1;
		if (StringUtil.isNotEmpty(page)) {
			if (StringUtil.isNotNum(page)) {
				getOrderResultVo.setMsg("page必须为数字");
				return getOrderResultVo;
			} else {
				_page = Integer.parseInt(page);
				if (_page <= 0) {
					getOrderResultVo.setMsg("page必须大于零");
					return getOrderResultVo;
				}
			}
		}
		Integer _quantity = 10;
		if (StringUtil.isNotEmpty(quantity)) {
			if (StringUtil.isNotNum(quantity)) {
				getOrderResultVo.setMsg("quantity必须为数字");
				return getOrderResultVo;
			} else {
				_quantity = Integer.parseInt(quantity);
				if (_quantity <= 0) {
					getOrderResultVo.setMsg("quantity必须大于零");
					return getOrderResultVo;
				}
			}
		}
		if (StringUtil.isEmpty(sign)) {
			getOrderResultVo.setMsg("sign不能为空");
			return getOrderResultVo;
		}

		// Token验证
		GetUserInfoVo userInfo = null;
		userInfo = CheckToken.getUserInfo(token);
		if (!"0000".equals(userInfo.getResp_status())) {
			getOrderResultVo.setMsg("token 验证失败");
			return getOrderResultVo;
		}
		return orderServieces
				.getOrderResult(token, result_id, _page, _quantity);
	}

	/**
	 * 退款交易查询结果查看
	 */
	@RequestMapping(value = "/get_order_refund_result", method = RequestMethod.POST)
	@ResponseBody
	public GetOrderResultVo getOrderRefundResult(
			@RequestParam(required = false) String token,
			@RequestParam(required = false) String result_id,
			@RequestParam(required = false) String page,
			@RequestParam(required = false) String quantity,
			@RequestParam(required = false) String sign) {
		StringBuilder sb = new StringBuilder();
		sb.append("token=" + token);
		sb.append(" result_id=" + result_id);
		sb.append(" page=" + page);
		sb.append(" quantity=" + quantity);
		sb.append(" sign=" + sign);
		if (logger.isInfoEnabled()) {
			logger.info("退款交易查询结果查看接口：" + sb);
		}
		GetOrderResultVo getOrderResultVo = new GetOrderResultVo();
		getOrderResultVo.setResp_status("9999");
		if (StringUtil.isEmpty(token)) {
			getOrderResultVo.setMsg("token不能为空");
			return getOrderResultVo;
		}
		if (StringUtil.isEmpty(result_id)) {
			getOrderResultVo.setMsg("result_id不能为空");
			return getOrderResultVo;
		}
		Integer _page = 1;
		if (StringUtil.isNotEmpty(page)) {
			if (StringUtil.isNotNum(page)) {
				getOrderResultVo.setMsg("page必须为数字");
				return getOrderResultVo;
			} else {
				_page = Integer.parseInt(page);
				if (_page <= 0) {
					getOrderResultVo.setMsg("page必须大于零");
					return getOrderResultVo;
				}
			}
		}
		Integer _quantity = 10;
		if (StringUtil.isNotEmpty(quantity)) {
			if (StringUtil.isNotNum(quantity)) {
				getOrderResultVo.setMsg("quantity必须为数字");
				return getOrderResultVo;
			} else {
				_quantity = Integer.parseInt(quantity);
				if (_quantity <= 0) {
					getOrderResultVo.setMsg("quantity必须大于零");
					return getOrderResultVo;
				}
			}
		}
		if (StringUtil.isEmpty(sign)) {
			getOrderResultVo.setMsg("sign不能为空");
			return getOrderResultVo;
		}

		// Token验证
		GetUserInfoVo userInfo = null;
		userInfo = CheckToken.getUserInfo(token);
		if (!"0000".equals(userInfo.getResp_status())) {
			getOrderResultVo.setMsg("token 验证失败");
			return getOrderResultVo;
		}
		return orderServieces.getOrderRefundResult(token, result_id, _page, _quantity);
	}

	/**
	 * 订单明细补全（更改商品明细）
	 */
	@RequestMapping(value = "/upd_order_info", method = RequestMethod.POST)
	@ResponseBody
	public UpdOrderInfoVo UpdOrderDetailInfo(
			@RequestParam(required = false) String token,
			@RequestParam(required = false) String order_id,
			@RequestParam(required = false) String detail,
			@RequestParam(required = false) String content,
			@RequestParam(required = false) String comment,
			@RequestParam(required = false) String sign) {
		StringBuilder sb = new StringBuilder();
		sb.append("token=" + token);
		sb.append(" order_id=" + order_id);
		sb.append(" detail=" + detail);
		sb.append(" comment=" + comment);
		sb.append(" sign=" + sign);
		if (logger.isInfoEnabled()) {
			logger.info("订单明细补全接口：" + sb);
		}
		UpdOrderInfoVo updOrderInfoVo = new UpdOrderInfoVo();
		if (StringUtil.isEmpty(token)) {
			updOrderInfoVo.setMsg("token不能为空");
			return updOrderInfoVo;
		}
		if (StringUtil.isEmpty(order_id)) {
			updOrderInfoVo.setMsg("order_id不能为空");
			return updOrderInfoVo;
		}
		if (StringUtil.isEmpty(sign)) {
			updOrderInfoVo.setMsg("sign不能为空");
			return updOrderInfoVo;
		}

		// Token验证
		GetUserInfoVo userInfo = null;
		userInfo = CheckToken.getUserInfo(token);
		if (!"0000".equals(userInfo.getResp_status())) {
			updOrderInfoVo.setMsg("token 验证失败！");
			return updOrderInfoVo;
		}
		return orderServieces.updOrderInfo(token, order_id, detail, content,comment);
	}

	/**
	 * 申请退款
	 */
	@RequestMapping(value = "/create_refund", method = RequestMethod.POST)
	@ResponseBody
	public CreateRefundVo createRefund(
			@RequestParam(required = false) String token,
			@RequestParam(required = false) String order_id,
			@RequestParam(required = false) String refund_fee,
			@RequestParam(required = false) String comment,
			@RequestParam(required = false) String sign) {
		StringBuilder sb = new StringBuilder();
		sb.append("token=" + token);
		sb.append(" order_id=" + order_id);
		sb.append(" refund_fee=" + refund_fee);
		sb.append(" comment=" + comment);
		sb.append(" sign=" + sign);
		if (logger.isInfoEnabled()) {
			logger.info("申请退款接口：" + sb);
		}
		CreateRefundVo createRefundVo = new CreateRefundVo();
		createRefundVo.setResp_status("9999");
		if (StringUtil.isEmpty(token)) {
			createRefundVo.setMsg("token不能为空");
			return createRefundVo;
		}
		if (StringUtil.isEmpty(order_id)) {
			createRefundVo.setMsg("order_id不能为空");
			return createRefundVo;
		}
		Integer _refund_fee = 1;
		if (StringUtil.isEmpty(refund_fee)) {
			createRefundVo.setMsg("refund_fee不能为空");
			return createRefundVo;
		} else {
			if (StringUtil.isNotNum(refund_fee)) {
				createRefundVo.setMsg("refund_fee必须为数字");
				return createRefundVo;
			} else {
				_refund_fee = Integer.parseInt(refund_fee);
				if (_refund_fee <= 0) {
					createRefundVo.setMsg("refund_fee必须大于0");
					return createRefundVo;
				}
			}
		}

		// Token验证
		GetUserInfoVo userInfo = CheckToken.getUserInfo(token);
		if (!"0000".equals(userInfo.getResp_status())) {
			createRefundVo.setMsg("token 验证失败！");
			return createRefundVo;
		}
		String operator_id = userInfo.getUuid();
		String operator_name = userInfo.getUser_name();
		return orderServieces.createRefund(token, order_id, _refund_fee,
				comment, operator_id, operator_name);
	}

	/**
	 * 退款复核
	 */
	@RequestMapping(value = "/allow_refund", method = RequestMethod.POST)
	@ResponseBody
	public AllowRefundVo allowRefund(
			@RequestParam(required = false) String token,
			@RequestParam(required = false) String order_id,
			@RequestParam(required = false) String refund_fee,
			@RequestParam(required = false) String comment,
			@RequestParam(required = false) String sign) {
		StringBuilder sb = new StringBuilder();
		sb.append("token=" + token);
		sb.append(" order_id=" + order_id);
		sb.append(" refund_fee=" + refund_fee);
		sb.append(" comment=" + comment);
		sb.append(" sign=" + sign);
		if (logger.isInfoEnabled()) {
			logger.info("退款复核接口：" + sb);
		}
		AllowRefundVo allowRefundVo = new AllowRefundVo();
		allowRefundVo.setResp_status("9999");
		if (StringUtil.isEmpty(token)) {
			allowRefundVo.setMsg("token不能为空");
			return allowRefundVo;
		}
		if (StringUtil.isEmpty(order_id)) {
			allowRefundVo.setMsg("order_id不能为空");
			return allowRefundVo;
		}
		Integer _refund_fee = 1;
		if (StringUtil.isEmpty(refund_fee)) {
			allowRefundVo.setMsg("refund_fee不能为空");
			return allowRefundVo;
		} else {
			if (StringUtil.isNotNum(refund_fee)) {
				allowRefundVo.setMsg("refund_fee必须为数字");
				return allowRefundVo;
			} else {
				_refund_fee = Integer.parseInt(refund_fee);
				if (_refund_fee <= 0) {
					allowRefundVo.setMsg("refund_fee必须大于0");
					return allowRefundVo;
				}
			}
		}

		// Token验证
		GetUserInfoVo userInfo = CheckToken.getUserInfo(token);
		if (!"0000".equals(userInfo.getResp_status())) {
			allowRefundVo.setMsg("token 验证失败！");
			return allowRefundVo;
		}
		String operator_id = userInfo.getUuid();
		String operator_name = userInfo.getUser_name();
		return orderServieces
				.allowRefund(token, order_id, _refund_fee,
						comment, operator_id, operator_name);
	}
}
